package com.zxy.employee.controller;

import com.zxy.base.dto.Result;
import com.zxy.base.util.ResultUtil;
import com.zxy.employee.entity.ResumeEntity;
import com.zxy.employee.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

@RestController
public class ResumeController {

    @Autowired
    private ResumeService resumeService;


    @PostMapping("/resumeUpload")
    public Result resumeUpload(Integer employeeId, MultipartFile file) throws IOException {

        String name = file.getOriginalFilename();

        resumeService.insertResume(new ResumeEntity(null,employeeId,name));

        File saveFile = new File(name);
        if(!saveFile.exists()) {
            saveFile.createNewFile();
        }
        file.transferTo(saveFile);
        return ResultUtil.success(name);
    }
}
